﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Upload.aspx.cs" Inherits="UpLoadImages_Upload" %>

<%@ Register Assembly="DevExpress.Web.ASPxEditors.v10.2, Version=10.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>上传项目成果图片</title>
    <link type="text/css" rel="stylesheet" href="web20110913.css" />
    <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        //控制窗体大小
        // window.open('Upload.aspx','','width=800,height=200')

        //此为批量上传图片JS代码
        //增加上传图片框
        var TfileUploadNum = 1; //记录图片选择框个数
        var Tnum = 1; //ajax上传图片时索引
        function TAddFileUpload() {
            var idnum = TfileUploadNum + 1;
            var str = "<tr><td class='tdClass'>项目成果图片" + idnum + "：</td>";
            str += "<td class='tdClass'><input name='' size='60' id='uploadImg" + idnum + "' type='file' /><span id='uploadImgState" + idnum + "'>";
            str += "</span></td></tr>";
            $("#imgTable").append(str);
            TfileUploadNum += 1;
        }

        //提交按钮事件，批量提交
        function TSubmitUploadImageFile() {
            $("#SubUpload").disabled = true;
            $("CancelUpload").disabled = true;
            $("AddUpload").disabled = true;
            setTimeout("TajaxFileUpload()", 1000);   //延迟上传时间
        }


        //延迟图片上传时间 在后台为图片重新命名
        function TajaxFileUpload() {
            var h = window.location.host;
            if (Tnum < TfileUploadNum + 1) {
                //准备提交处理
                $("#uploadImgState" + Tnum).html("<img src=loading.gif />");
                //开始提交
                $.ajax
			({
			    type: "POST",
			    url: "http://" + h + "/CSSPMS/UpLoadImages/AjaxUpload.ashx", //.ashx文件路径
			    data: { upfile: $("#uploadImg" + Tnum).val(), category: $("#pcategory").val() },
			    success: function (data, status) {
			        var stringArray = data.split("|");

			        if (stringArray[0] == "1") {
			            //stringArray[0]    成功状态(1为成功，0为失败)
			            //stringArray[1]    上传成功的文件名
			            //stringArray[2]    消息提示
			            $("#uploadImgState" + Tnum).html("<img src=ok.gif />"); //+stringArray[1]+"|"+stringArray[2]);
			        }
			        else {
			            //上传出错
			            $("#uploadImgState" + Tnum).html("<img src=error.gif />" + stringArray[2]); //+stringArray[2]+"");
			        }
			        Tnum++;
			        setTimeout("TSubmitUploadImageFile()", 0);
			        $("#txtFilePath").val(stringArray[1]);
			    }
			});
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="panel upload_title">
        <h1>
            上传项目成果图片</h1>
    </div>
    <div class="panel des">
        <span>注释:</span> 每个项目可对应上传多张图片。
    </div>
    <div class="panel uploadbox">
        <table cellpadding="0" cellspacing="0" border="0" id="imgTable" class="table3">
            <tr>
                <td style="width: 150px; text-align: right;">
                    请选择项目成果图片：
                </td>
                <td>
                    <asp:FileUpload ID="uploadImg1" runat="server" Width="366px" />
                    <span id="uploadImgState1"></span>
                </td>
                <td colspan="2" style="text-align: right;">
                    <asp:Button ID="SubUpload" class="ManagerButton" runat="server" Text="确定图片" OnClientClick="TSubmitUploadImageFile();return false;"
                        Width="55px" Height="30px" />
                    <asp:Button ID="CancelUpload" class="ManagerButton" Width="55px" Height="30px" OnClientClick="javascript:history.go(-1);"
                        runat="server" Text="  取  消" />
                </td>
            </tr>
            <tr>
                <td style="width: 150px; text-align: right;">
                    服务器图片路径：
                </td>
                <td>
                    <asp:TextBox ID="txtFilePath" runat="server" Width="365px"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td style="width: 150px; text-align: right;">
                    图片描述：
                </td>
                <td>
                    <asp:TextBox ID="txtDes" runat="server" Width="365px" TextMode="MultiLine"></asp:TextBox>
                </td>
                <td style="text-align: right;">
                    <asp:Button ID="btnOk" runat="server" Text="确认上传" OnClick="btnOk_Click" Width="55px"
                        Height="30px" />
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="4" style="text-align: right; padding-top: 20px;">
                    <dx:ASPxHyperLink ID="ASPxHyperLink1" runat="server" Text="<<<返回项目成效登记页" NavigateUrl="~/ProResult.aspx">
                    </dx:ASPxHyperLink>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>
